import axios from 'axios'
import { MessageBox, Message } from 'element-ui';
import { getToken } from "@/utils/auth.js";

// create an axios instance
const service = axios.create({
  baseURL: "/api", // url = base url + request url
  timeout: 500000 // request timeout
})

service.interceptors.request.use(
  config => {
    //config.headers['ngrok-skip-browser-warning'] = "true";
    const token = getToken();
    if(token){
      config.headers['satoken'] = token;
    }
    return config;
  },
  error => {
    console.log(error);
    return Promise.reject(error);
  }
)

service.interceptors.response.use(
  response => {
    return response;
  },
  error => {
    console.log('err' + error); // for debug
    return Promise.reject(error);
  }
)

export default service
